/* GUI CONVERTED from rcrbrp1a.p (converter v1.76) Thu Aug 29 21:43:48 2002 */
/* rcrbrp1a.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.10.1.15 $                                                               */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.4    LAST MODIFIED: 09/13/93   BY: WUG *H109*                  */
/* REVISION: 7.4    LAST MODIFIED: 08/09/94   BY: bcm *H473*                  */
/* REVISION: 7.4    LAST MODIFIED: 11/29/94   BY: afs *H608*                  */
/* REVISION: 8.5    LAST MODIFIED: 03/04/96   BY: kjm *H0J9*                  */
/* REVISION: 8.5    LAST MODIFIED: 12/05/96   BY: *H0PP* Ajit Deodhar         */
/* REVISION: 8.5    LAST MODIFIED: 08/20/97   BY: *H1D5* Aruna Patil          */
/* REVISION: 8.5    LAST MODIFIED: 08/24/97   BY: *H1DG* Suresh Nayak         */
/* REVISION: 8.5    LAST MODIFIED: 09/22/97   BY: *H1FK* Niranjan Ranka       */
/* REVISION: 8.5    LAST MODIFIED: 10/22/97   BY: *H1G6* Seema Varma          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 08/06/99   BY: *N01F* Kedar Deherkar     */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Patti Gaultney     */
/* REVISION: 9.1      LAST MODIFIED: 10/06/99   BY: *J3LX* Poonam Bahl        */
/* REVISION: 9.1      LAST MODIFIED: 06/27/00   BY: *N0DM* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* REVISION: 9.1      LAST MODIFIED: 12/29/00   BY: *M0Z1* Kaustubh K.        */
/* REVISION: 9.1      LAST MODIFIED: 09/25/00   BY: *N0WD* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *H605*                    */
/* Revision: 1.10.1.10     BY: Katie Hilbert    DATE: 04/01/01 ECO: *P002*    */
/* Revision: 1.10.1.12     BY: Murali Ayyagari  DATE: 06/11/01 ECO: *M19X*    */
/* Revision: 1.10.1.13     BY: Santosh Rao      DATE: 03/08/02 ECO: *N1C9*    */
/* Revision: 1.10.1.14     BY: Ashish M.        DATE: 03/21/02 ECO: *M1WV*    */
/* $Revision: 1.10.1.15 $            BY: Rajaneesh S.     DATE: 08/23/02 ECO: *N1S4*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* RETROBILL REPORT SUBPROGRAM */

/*************INPUT/OUTPUT PARAMETERS *****************************************
 *            INPUT  CUST                        SOLD-TO CUSTOMER
 *            INPUT  AUTH                        AUTHORIZATION NUMBER
 *            INPUT  AMT                         AMOUNT
 *            INPUT  ACCT                        ACCOUNT
 *            INPUT  SUB                         SUBACCOUNT
 *            INPUT  CC                          COST CENTER
 *            INPUT  PO                          PURCHASE ORDER
 *            INPUT  PART                        ITEM NUMBER/RETROBILL
 *            INPUT  P_SHIPTO                    SHIP-TO
 *            INPUT  P_SITEFROM                  SHIP-FROM
 *            INPUT  P_BILLTO                    BILL-TO
 *            OUTPUT MEMO_NBR                    MEMO NUMBER
 *            OUTPUT SONBR                       SALES ORDER NUMBER
 *            INPUT-OUTPUT ERROR_COUNT
**************************************************************************** */

{mfdeclre.i}
{cxcustom.i "RCRBRP1A.P"}
{gplabel.i}

define input parameter cust as character.
define input parameter auth as character.
define input parameter amt as decimal.
define input parameter acct as character.
define input parameter sub  as character               no-undo.
define input parameter cc   as character format "x(4)" no-undo.
define input parameter po   as character.
define input parameter part as character.
define input parameter p_shipto like scx_shipto no-undo.
define input parameter p_sitefrom like pt_site  no-undo.
define input parameter p_billto like ih_bill    no-undo.
define output parameter memo_nbr as character.
define output parameter sonbr as character.
define input-output parameter error_count as integer no-undo.
define shared stream repout.
define variable work_i_file as   character no-undo.
define variable work_o_file as   character no-undo.
define variable next_so     like soc_so    no-undo.
define variable i           as   integer   no-undo.
define variable rmks        as   character no-undo.
define variable single_ln   as   character no-undo.

define new shared variable so_recno as recid.
define new shared variable inv_date like ar_date.
define new shared variable next_inv_nbr like soc_inv.
define new shared variable comb_inv_nbr like so_inv_nbr.
define new shared variable next_inv_pre like soc_inv_pre.

define variable linefield as character format "x(40)" no-undo.
define variable soc_pc_line like mfc_logical no-undo.
define variable save_batchrun like batchrun no-undo.
define variable site          like pt_site no-undo.
define variable multi_sls   like mfc_logical no-undo.
define variable got_sls     like mfc_logical no-undo.
define variable curr_diff   like mfc_logical no-undo.
define variable soc_pim_isb like mfc_logical no-undo.
define variable cust_tax    like mfc_logical no-undo.
define variable cust_freight like mfc_logical no-undo.
define variable no_freight like mfc_logical no-undo.
define variable no_disp_freight like mfc_logical no-undo.
define variable no_intrastat like mfc_logical initial "no" no-undo.
define variable q as character initial "~"" no-undo.
define variable use_defaults like mfc_logical initial "no" no-undo.
{&RCRBRP1A-P-TAG1}
define variable l_msg as character format "X(80)" no-undo.

assign
   rmks      = getTermLabel("RETROBILL_AMENDMENT",20) + " " + auth
   single_ln = getTermLabel("SINGLE",2).

{pxmsg.i &MSGNUM    = 4108
         &ERRORLEVEL = 4
         &MSGBUFFER  = l_msg}

assign
   work_i_file = mfguser + ".rbi"
   work_o_file = mfguser + ".rbo".

for first soc_ctrl
   fields(soc_hcmmts soc_inv_pre soc_lcmmts
          soc_so soc_so_pre)
   no-lock:
end. /* FOR FIRST soc_ctrl */

for first mfc_ctrl
   fields(mfc_field mfc_logical)
   where mfc_field = "soc_pc_line"
   no-lock :
end. /* FOR FIRST mfc_ctrl */

if available mfc_ctrl
then
   soc_pc_line = mfc_logical.

for first mfc_ctrl
   fields(mfc_field mfc_logical)
   where mfc_field = "soc_pim_isb"
   no-lock :
end. /* FOR FIRST mfc_ctrl */

if available mfc_ctrl
then
   soc_pim_isb = mfc_logical.

for first si_mstr
   fields(si_site)
   no-lock
   where si_site >= "":
end. /* FOR FIRST si_mstr */

for first pt_mstr
   fields(pt_isb pt_part pt_taxable)
   where pt_part = part
   no-lock :
end. /* FOR FIRST pt_mstr */

/* REMEMBER CURRENT "NEXT" SO NUMBER */
next_so = soc_so.

/* IF ALL THE FIELDS ARE BLANK THEN DEFAULTS ARE TO BE USED.         */
if  acct = ""
and sub = ""
and cc = ""
then
   use_defaults = true.

/* ALL CHARACTER FIELDS SHOULD BE ENCLOSED IN QUOTES OTHERWISE       */
/* IT COULD CAUSE PROBLEMS DURING PENDING INVOICE MAINTENANCE UPLOAD */

if po = ""
then
   po = "-".
else
/* VARIABLE Q REPRESENTS DOUBLE QUOTES */
   po = q + po + q.

/* HERE WE SET VARIOUS FLAGS FOR VARIOUS CUSTOMER SITUATIONS */
assign
   multi_sls = false
   curr_diff = false
   cust_tax = false
   got_sls = false
   cust_freight = false
   no_freight = false
   no_disp_freight = false.

for first ad_mstr
  fields(ad_addr ad_taxable)
  where ad_addr = cust
  no-lock:
end. /* FOR FIRST ad_mstr */

if available ad_mstr
then
   if ad_taxable
   then
      cust_tax = true.

{&RCRBRP1A-P-TAG2}

for first cm_mstr
   fields(cm_addr cm_curr cm_fr_list cm_slspsn)
   where cm_addr = cust
   no-lock:
end. /* FOR FIRST cm_mstr */

if available cm_mstr
then do:
   if cm_slspsn[2] <> "" or
      cm_slspsn[3] <> "" or
      cm_slspsn[4] <> ""
   then
      multi_sls = true.

   if cm_curr <> base_curr
   then
      curr_diff = true.
   if cm_fr_list <>  ""
   then
      cust_freight = true.
   if cm_slspsn[1] <>  ""
   then
      got_sls = true.
end. /* IF AVAILABLE cm_mstr */

/* BUILD INPUT FILE TO PENDING INVOICE MAINT */
output to value(work_i_file).

/* ALL CHARACTER FIELDS SHOULD BE ENCLOSED IN QUOTES OTHERWISE       */
/* IT COULD CAUSE PROBLEMS DURING PENDING INVOICE MAINTENANCE UPLOAD */

/* VARIABLE Q REPRESENTS DOUBLE QUOTES                               */
assign
   cust       = q + cust       + q
   p_billto   = q + p_billto   + q
   p_shipto   = q + p_shipto   + q
   part       = q + part       + q
   site       = q + site       + q
   p_sitefrom = q + p_sitefrom + q
   .

put unformatted
   skip(1)
   cust skip
   p_billto skip
   p_shipto skip
   "- - - - - " po " ~"" rmks "~"" skip.

if curr_diff
then
   put unformatted skip(1).
{&RCRBRP1A-P-TAG3}
put unformatted skip(1).

put unformatted "- - - - - - - - " no_freight " " no_disp_freight " " no_intrastat skip.
if multi_sls
then
   put unformatted skip(1).

if soc_hcmmts
then
   put unformatted "." skip.

put unformatted "." skip
   single_ln skip.

put unformatted
   skip(1)
   part skip
   p_sitefrom skip.

if amt < 0
then
   put unformatted "-1" skip.              /* QUANTITY */
else
   put unformatted "1" skip.               /* QUANTITY */
put unformatted skip(1).         /* SKIP PRICING/PROMOTIONS POPUP */

put unformatted
   absolute(amt) skip         /* LIST PRICE */
   absolute(amt) skip         /* NET PRICE  */
   .

if not available pt_mstr
then
   /* DESCRIPTION FOR MEMO ITEM */
   put unformatted
   "~" ~"" skip
   .

/* THE FOLLOWING BLOCK OF CODE IS PART OF THE BUILD OF AN INPUT FILE TO       */
/* PENDING INVOICE MAINTENANCE.                                               */
/* THIS IS SIMILAR TO A CIM LOAD. TO UNDERSTAND HOW THE BLOCK WORKS VIEW      */
/* PENDING INVOICE MAINTENANCE.  THE CODE BELOW SIMULATES INPUT TO FRAME D,   */
/* WHICH IS THE LINE DETAIL FRAME (SEE SOIVMTA2.P).                           */
/* WHEN DEFAULT ACCTS = NO IN 7.13.13.3 THEN THE RETROBILL ACCT VALUES        */
/* ARE ENTERED INTO THE PENDING INVOICE.                                      */

/* IF SALESPERSON NON-BLANK COMM%[1] FIELD IS AVAILABLE FOR INPUT.   */
if got_sls
then
   put unformatted "- - - ".  /* TAB THRU LOC, LOT/SERIAL, COMM%[1].*/
else
   put unformatted "- - ".     /* TAB THRU LOC, LOT/SERIAL.          */

if use_defaults = true
then
   put unformatted "- - - ".   /* USE DEFAULT ACCT, SUBACCT, CC.     */
else
   /* USE RETROBILL ACCT, SUBACCOUNT AND COST CENTER.                */
   /* VALUES MUST BE ENCLOSED IN DOUBLE QUOTES. VARIABLE Q           */
   /* REPRESENTS DOUBLE QUOTES.                                      */
   put unformatted q acct q space q sub q space q cc q.
   put unformatted "- - - - - - - - - M".
   put unformatted skip.          /* SIMULATES GO (F1 IN CHAR).         */

if available pt_mstr
and pt_taxable = yes
and cust_tax
then
   put unformatted skip(1).
{&RCRBRP1A-P-TAG4}

if multi_sls
then
   put unformatted skip(1).

/* IF THE FREIGHT LIST IS <> "" AND CALCULATE FREIGHT = yes AND
   DISPLAY WEIGHTS = yes THEN SIMULATE F4. */
if cust_freight
and no_freight = true
and no_disp_freight = true
then
   put unformatted "." skip.

if available pt_mstr
and pt_isb and soc_pim_isb
then
   put unformatted "." skip.                     /* ISB POPUP */
if soc_lcmmts
then
   put unformatted "." skip.
put unformatted
   "." skip
   "." skip
   skip(1)
   skip(1)
   "." skip.

output close.

/* LOCK AND HOLD THE qad_wkfl SO THAT ONLY ONE PROGRAM */
/* CAN CREATE INVOICE NUMBERS AT A TIME                */
{gprun.i ""sorp10a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


/* INVOKE PENDING INVOICE MAINT */
input from value(work_i_file).

output to value(work_o_file) keep-messages.

pause 0.
save_batchrun = batchrun.
if not batchrun
then
   batchrun = true.
{gprun.i ""soivmt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

pause before-hide.
if batchrun <> save_batchrun
then
   batchrun = save_batchrun.
input close.
output close.

/* GO FIND THE SO THAT WAS CREATED */
assign
   sonbr    = ""
   memo_nbr = "".

do i = 0 to 100:
   for first so_mstr
      fields(so_invoiced so_inv_date so_inv_nbr
             so_nbr so_rmks so_to_inv)
      where so_nbr = soc_so_pre + string(next_so + i)
      no-lock :
   end. /* FOR FIRST so_mstr */

   if available so_mstr
   and so_rmks = rmks
   then do:
      sonbr = so_nbr.
      leave.
   end. /* IF AVAILABLE so_mstr */
end. /* DO i = 0 .. */

if sonbr = ""
then do:
   do i = 0 to 100:
      for first so_mstr
         fields(so_invoiced so_inv_date so_inv_nbr
                so_nbr so_rmks so_to_inv)
         where so_nbr = soc_so_pre + string(i)
         no-lock:
      end. /* FOR FIRST so_mstr */
      if available so_mstr
      and so_rmks = rmks
      then do:
         sonbr = so_nbr.
         leave.
      end. /* IF AVAILABLE so_mstr */
   end. /* Do i = 0 */
end. /* IF sonbr = "" */

if sonbr = ""
then do:
   /* DIDN'T FIND AN SO, SO REPORT ANY ERROR MESSAGES */

   put stream repout
      skip(1)
      l_msg
      skip.

   input from value(work_o_file) no-echo.

   repeat:

      import unformatted linefield.

      if linefield begins "**"
      or linefield begins getTermLabel("ERROR",8) + ": "
      then do:
         put stream repout unformatted linefield skip.
         error_count = error_count + 1.
      end. /* IF linefield ........ */
   end. /* REPEAT */

   input close.
   put stream repout skip(1).
end. /* IF sonbr = "" */

else do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

   /* ASSIGN AN INVOICE NUMBER TO THE SO */
   assign
      so_recno     = recid(so_mstr)
      next_inv_pre = soc_inv_pre
      next_inv_nbr = soc_inv - 1.

   {gprun.i ""sosoina.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   {gprun.i ""sorp10b.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   release qad_wkfl.
   release soc_ctrl.

   find so_mstr
      where recid(so_mstr) = so_recno
      exclusive-lock.

   assign
      so_invoiced = no
      so_to_inv   = yes
      so_inv_date = ?
      memo_nbr    = so_inv_nbr.
end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* ELSE DO */
